package com.ruoyi.mobile.api;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageSerializable;
import com.ruoyi.common.core.domain.AjaxResults;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.qsng.domain.*;
import com.ruoyi.qsng.service.IKActivityPurchaseService;
import com.ruoyi.qsng.service.IKCoursePurchaseService;
import com.ruoyi.qsng.service.ITStudentCertificateService;
import com.ruoyi.qsng.service.ITStudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 奖状
 *
 * @author gk
 * @date 2023-08-15
 */
@Api(tags = "奖状")
@RestController
@RequestMapping
public class StudentCertificateController {

    @Autowired
    private ITStudentService tStudentService;

    @Autowired
    private ITStudentCertificateService tStudentCertificateService;

    @Autowired
    private IKActivityPurchaseService kActivityPurchaseService;

    @Autowired
    private IKCoursePurchaseService kCoursePurchaseService;

    /**
     * 查询学生信息列表
     */
    @ApiOperation(value = "查询学生信息列表")
    @GetMapping("/weixin/student/studentList")
    public AjaxResults<List<TStudent>> studentList(
            @RequestParam(required = false, defaultValue = "1") Integer pageNum,
            @RequestParam(required = false, defaultValue = "10") Integer pageSize,TStudent tStudent)
    {
        PageHelper.startPage(pageNum, pageSize);
        List<TStudent> list = tStudentService.selectTStudentList(tStudent);
        return AjaxResults.success(new PageSerializable<>(list));
    }

    /**
     * 查询学生信息详情
     */
    @ApiOperation(value = "查询学生信息详情")
    @GetMapping("/weixin/student/{id}")
    public AjaxResults getInfo(@PathVariable("id") Long id)
    {
        TStudent tStudent=tStudentService.selectTStudentById(id);
        //活动
        KActivityPurchase kActivityPurchase =new KActivityPurchase();
        kActivityPurchase.setIdCard(tStudent.getIdCard());
        List<KActivityPurchase> kActivityPurchaseList=kActivityPurchaseService.selectKActivityPurchaseList(kActivityPurchase);
        tStudent.setActivityNum(Long.valueOf(kActivityPurchaseList.size()));

        //参加活动
        String str ="";
        int i =0;
        for (KActivityPurchase kActivityPurchase1:kActivityPurchaseList) {
            if(i==0){
                str=kActivityPurchase1.getName();
            }else {
                str = str +","+ kActivityPurchase1.getName();
            }
            i++;
        }
        tStudent.setParticipateInActivities(str);

        //报名
        KCoursePurchase  kCoursePurchase =new KCoursePurchase();
        kCoursePurchase.setState(1);
        kCoursePurchase.setNickCard(tStudent.getIdCard());
        List<KCoursePurchase> kCoursePurchaseList= kCoursePurchaseService.selectKCoursePurchaseDataList(kCoursePurchase);
        tStudent.setApplicationNum(Long.valueOf(kCoursePurchaseList.size()));

        return AjaxResults.success(tStudent);
    }

    /**
     * 分页查询获奖信息
     */
    @ApiOperation(value = "分页查询获奖信息")
    @GetMapping("/weixin/studentCertificate/studentCertificateList")
    public AjaxResults<List<TStudentCertificate>> studentCertificateList(
            @RequestParam(required = false, defaultValue = "1") Integer pageNum,
            @RequestParam(required = false, defaultValue = "10") Integer pageSize, TStudentCertificate tStudentCertificate)
    {
        PageHelper.startPage(pageNum, pageSize);
        List<TStudentCertificate> list = tStudentCertificateService.selectTStudentCertificateList(tStudentCertificate);
        return AjaxResults.success(new PageSerializable<>(list));
    }

}
